package com.tancire.web.controller.system;

import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.core.page.TableDataInfo;
import com.tancire.common.enums.BusinessType;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.file.domain.SysFiles;
import com.tancire.file.service.ISysFilesService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 文件Controller
 *
 * @author chenchao
 * @date 2022-12-15
 */
@RestController
@RequestMapping("/files/sysFiles")
public class SysFilesController extends BaseController {

    @Resource
    private ISysFilesService sysFilesService;

    /**
     * 查询文件列表
     */
    @PreAuthorize("@ss.hasPermi('files:sysFiles:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysFiles sysFiles) {
        startPage();
        List<SysFiles> list = sysFilesService.selectSysFilesList(sysFiles);
        return getDataTable(list);
    }

    /**
     * 导出文件列表
     */
    @PreAuthorize("@ss.hasPermi('files:sysFiles:export')")
    @Log(title = "文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysFiles sysFiles) {
        List<SysFiles> list = sysFilesService.selectSysFilesList(sysFiles);
        ExcelUtil<SysFiles> util = new ExcelUtil<SysFiles>(SysFiles.class);
        util.exportExcel(response, list, "文件数据");
    }

    /**
     * 获取文件详细信息
     */
    @PreAuthorize("@ss.hasPermi('files:sysFiles:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(sysFilesService.selectSysFilesById(id));
    }

    /**
     * 新增文件
     */
    @PreAuthorize("@ss.hasPermi('files:sysFiles:add')")
    @Log(title = "文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysFiles sysFiles) {
        return toAjax(sysFilesService.insertSysFiles(sysFiles));
    }

    /**
     * 修改文件
     */
    @PreAuthorize("@ss.hasPermi('files:sysFiles:edit')")
    @Log(title = "文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysFiles sysFiles) {
        return toAjax(sysFilesService.updateSysFiles(sysFiles));
    }

    /**
     * 删除文件
     */
    @PreAuthorize("@ss.hasPermi('files:sysFiles:remove')")
    @Log(title = "文件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysFilesService.deleteSysFilesByIds(ids));
    }


}
